package com.core.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 *
 * @author lxf
 * @date 2018/7/5 11:16
 * To change this template use Editor | File and Code Templates.
 */
public class AtomicTest {

    public static AtomicInteger integer = new AtomicInteger(0);

    public static void src() {
        integer.incrementAndGet();
    }


    public static void main(String[] args) {
        Thread[] threads = new Thread[20];
        for (int j = 0; j < 20; j++) {
            threads[j] = new Thread(() -> {
                for (int k = 0; k < 10000; k++) {
                    src();
                }
            });
            threads[j].start();
        }
        while (Thread.activeCount() > 1) {
            Thread.yield();
        }
        System.out.println(integer);
    }

}
